package com.imooc.common.thread;


class MyRunnable implements Runnable {

    private int ticketsCount = 5;

    @Override
    public void run() {
        while (ticketsCount>0){
            ticketsCount--;
            System.out.println(Thread.currentThread().getName()+"买了1张票,剩余票数为:"+ticketsCount);
        }
    }
}
public class TircketsRunnable {

    public static void main(String[] args) {
        MyRunnable myRunnable1 = new MyRunnable();
        // 创建三个线程来模拟三个售票窗口
        Thread t1 = new Thread(myRunnable1,"窗口1");
        Thread t2 = new Thread(myRunnable1,"窗口2");
        Thread t3 = new Thread(myRunnable1,"窗口3");

        t1.start();
        t2.start();
        t3.start();

    }
}
